<script setup>
import { RouterView } from 'vue-router'
import { onMounted, ref, getCurrentInstance, watch } from 'vue'
import { useRouter } from 'vue-router'
import { wxShare } from '@/utils/wxShare.js'

const router = useRouter()

// const isOff = ref(true)
// let micon = ref(new URL('@/assets/img/music_on.png', import.meta.url).href)

// 刷新
if (router.path !== '/') {
  router.replace('/')
}

// // 背景音乐管理器
// function BGMAutoPlayMgr(url) {
//   this.audioContext = new (window.AudioContext ||
//     window.webkitAudioContext ||
//     window.mozAudioContext)()
//   this.sourceNode = null
//   this.buffer = null
//   this.isPlayingBGM = false
//   this.toggleBGM = function () {
//     if (typeof this.sourceNode == 'object') {
//       if (this.isPlayingBGM) {
//         this.sourceNode.stop()
//         this.isPlayingBGM = false
//       } else this._playSourceNode()
//     }
//   }
//   this._playSourceNode = function () {
//     const audioContext = this.audioContext
//     audioContext.resume()
//     const _sourceNode = audioContext.createBufferSource()
//     _sourceNode.buffer = this.buffer
//     _sourceNode.loop = true
//     _sourceNode.connect(audioContext.destination)
//     _sourceNode.start(0)
//     this.sourceNode = _sourceNode
//     this.isPlayingBGM = true
//   }
//   let loadAndAutoPlay = (audioUrl) => {
//     const audioContext = this.audioContext
//     const xhr = new XMLHttpRequest()
//     xhr.open('GET', audioUrl, true)
//     xhr.responseType = 'arraybuffer'
//     xhr.onreadystatechange = () => {
//       if (xhr.status < 400 && xhr.status >= 200 && xhr.readyState === 4) {
//         audioContext.decodeAudioData(xhr.response, (buffer) => {
//           this.buffer = buffer
//           // WeixinJSBridge 微信浏览器内置对象
//           WeixinJSBridge.invoke('getNetworkType', {}, () => this._playSourceNode())
//         })
//       }
//     }
//     xhr.send()
//   }
//   // 播放
//   loadAndAutoPlay(url)
//   loadAndAutoPlay = null
//   this.isOff = false //按钮状态
// }
// // 判断是否是安卓
// const CheckIsAndroid = () => {
//   var browser = {
//     versions: (function () {
//       var u = navigator.userAgent,
//         app = navigator.appVersion
//       return {
//         //移动终端浏览器版本信息
//         ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
//         android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器 //u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
//         iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
//         iPad: u.indexOf('iPad') > -1 //是否iPad
//       }
//     })()
//   }
//   //if (browser.versions.iPhone || browser.versions.iPad || browser.versions.ios) {
//   //    return false;
//   //}
//   if (browser.versions.android) return true
//   return false
// }
// // 初始化音乐自动播放
// const initBGM = () => {
//   const bgm = new BGMAutoPlayMgr(new URL('@/assets/media/bgm.mp3', import.meta.url).href)
//   setTimeout(() => {
//     if (CheckIsAndroid()) {
//       //如果是Android
//       bgm.toggleBGM()
//     }
//   }, 500)
//   let ctrlbtn = document.getElementById('ctrlbtn')
//   ctrlbtn.addEventListener('click', () => {
//     bgm.toggleBGM()
//     isOff.value = !isOff.value
//   })
// }

// watch(isOff, (newVal) => {
//   if (newVal) {
//     micon.value = new URL('@/assets/img/music_on.png', import.meta.url).href
//   } else {
//     micon.value = new URL('@/assets/img/music_off.png', import.meta.url).href
//   }
// })

onMounted(() => {
  // initBGM()
  wxShare({
    title: '标题...',
    desc: '描述...',
    link: '',
    imgUrl: ''
  })
})
</script>

<template>
  <!-- <div class="musicicon">
    <img :src="micon" id="ctrlbtn" />
  </div> -->
  <RouterView />
</template>

<style lang="scss">
@font-face {
  font-family: 'SourceHanSansCN';
  font-weight: normal;
  src: url('https://cdn.mahelei.com/fonts/SourceHanSansCN-Regular.otf');
}
#app {
  width: 100%;
  height: 100%;
  background: #ffffff;
  font-family: 'SourceHanSansCN';
  color: #333;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
// 基础box
.box {
  position: relative;
  width: 100%;
  height: 100%;
}
.clmcenter {
  display: flex;
  flex-flow: column nowrap;
  justify-content: center;
  align-items: center;
}
.clmstart {
  display: flex;
  flex-flow: column nowrap;
  justify-content: flex-start;
  align-items: center;
}
.bg {
  background: url('@/assets/img/bg.jpg') no-repeat center center;
  background-size: 100% 100%;
}

// 按钮动画
.btnani {
  animation: btnanito 2s linear infinite;
}
@keyframes btnanito {
  0% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
  }
}

// 文字超出隐藏，超出部分用省略号表示
.ellipsis {
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}
.ellipsis-2 {
  word-break: break-all;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}
.musicicon {
  position: absolute;
  top: 30px;
  right: 30px;
  width: 60px;
  height: 60px;
  z-index: 9;
  border-radius: 50%;
  overflow: hidden;
  img {
    display: block;
    width: 100%;
  }
}
/*select和input设置相同大小*/
select,
input {
  appearance: none;
  -moz-appearance: none;
  -webkit-appearance: none;
  border-style: none;
  padding: 0;
  box-sizing: border-box;
  -moz-box-sizing: border-box;
  -webkit-box-sizing: border-box;
}
select:focus,
input:focus {
  outline: 0;
}
select {
  // background: #ffffff url(./assets/img/icon.png) no-repeat right center;
  background-size: 5% auto !important;
  background-position: right 3% top 1rem;
  text-align: center;
  text-align-last: center;
}
select::-ms-expand {
  display: none;
}
/*去除a标签点击时出现闪现黑背景  ——手机端*/
a,
a:hover,
a:active,
a:visited,
a:link,
a:focus,
img {
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  -webkit-tap-highlight-color: transparent;
  outline: none;
  background: none;
  text-decoration: none;
}
// 禁止选中文本
p,
span,
a,
i,
div {
  -webkit-user-select: none;
  -moz-user-select: none;
  -khtml-user-select: none;
  user-select: none;
}
</style>
